package org.mozhu.simple.rpc.server.network;

import org.mozhu.simple.rpc.common.RpcException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.channels.SelectionKey;
import java.util.Map;

public class PlaintextChannelBuilder implements ChannelBuilder {
    private static final Logger log = LoggerFactory.getLogger(PlaintextChannelBuilder.class);
    private Map<String, ?> configs;

    public void configure(Map<String, ?> configs) throws RpcException {
        this.configs = configs;
    }

    public RpcChannel buildChannel(String id, SelectionKey key, int maxReceiveSize) throws RpcException {
        try {
            PlaintextTransportLayer transportLayer = new PlaintextTransportLayer(key);
            return new RpcChannel(id, transportLayer, maxReceiveSize);
        } catch (Exception e) {
            log.warn("Failed to create channel due to ", e);
            throw new RpcException(e);
        }
    }

    public void close() {
    }

}